/**
 * @Description :  配置的动态路由
 * @author : August_xiao 1932794922@qq.com
 * @date : 2022-03-18 22:21
 */

// 动态路由
const dynamicRouter = [
  // {
  //   path: '/about',
  //   name: 'About',
  //   component: () => import(/* webpackChunkName: "group-dynamic-router" */'@/views/about/About.vue'),
  //   meta: {
  //     //页面标题名称
  //     title:'关于我的',
  //     KeepAlive: true,
  //     //图标
  //     icon:"",
  //     menuName:'菜单名称'
  //   }
  // },
  // {
  //   path: '/tag',
  //   name: 'Tag',
  //   component: () => import(/* webpackChunkName: "group-dynamic-router" */ '@/views/tag/Tag.vue'),
  //   meta: {
  //     title:'标签'
  //   }
  // },
]

/**
 * 动态组装路由
 * @param data
 */

const setNavRouterPathList = (data) => {
  const setRouter = []
  for (let i = 0; i < data.length; i++) {
    setRouter.push({
      path: `${data[i].path}`,
      name: data[i].name,
      alias: data[i].alias,
      // redirect:item.redirect
      children: [],
      meta: {
        KeepAlive: data[i].keepAlive,
        title: data[i].title,
        icon: data[i].icon,
        menuName: data[i].menuName
      },
      component: () => import(`@/views/${data[i].component}.vue`)
    })
    if (data[i].children && data[i].children.length > 0) {
      setRouter[i].children.push(...setNavRouterPathList(data[i].children))
    }
  }
  // console.log(data)
  // data.forEach(item => {
  //   setRouter.push({
  //     path: item.path,
  //     name: item.name,
  //     alias: item.alias,
  //     // redirect:item.redirect
  //     children: setNavRouterPathList(item.children),
  //     meta: {
  //       KeepAlive: item.keepAlive,
  //       title: item.title,
  //       icon: item.icon,
  //       menuName: item.menuName
  //     },
  //     component: () => import(`@/views/${item.component}.vue`),
  //   })
  // if (item.children && item.children.length > 0) {
  //   item.children.forEach((subItem) => {
  //     setRouter.push()
  //   })
  //   // setRouter.push(setNavRouterPathList(item.children))
  //   //如果有子菜单，则再次执行创建路由方法（递归）
  //   //   item.push(...setNavRouterPathList(item.children))
  // }
  // })
  return setRouter
}

export { setNavRouterPathList, dynamicRouter }
